package com.cww.study.config;

import io.seata.spring.annotation.GlobalTransactionScanner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: cww_project
 * @description:
 * @author: 陈英俊
 * @create: 2022-03-08 14:10
 */
@ConditionalOnProperty(
        prefix = "config",
        name = {"enableGlobaltransaction"},
        havingValue = "true"
)
@Configuration
public class GlobalTransactionAutoConfiguration {
    private final ApplicationContext applicationContext;

    public GlobalTransactionAutoConfiguration(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean
    public GlobalTransactionScanner globalTransactionScanner() {
        String applicationName = this.applicationContext.getEnvironment().getProperty("spring.application.name");
        return new GlobalTransactionScanner(applicationName, "cl_tx_group");
    }
}